package com.yidu.t299.dao.ssk;
import com.yidu.t299.domain.ssk.PerformanceStat;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

/**
 * @author 粟术康
 * @version 1.0
 * @description
 * @date:2023/3/10 10:39
 */
@Mapper
public interface PerformanceStatMapper {
    /**
     * 添加绩效信息
     * @param performanceStat 绩效对象
     * @return 影响的行数(返回1则为成功)
     */
    @Insert({"insert into performance_stat (per_id,record_id,student_id,class_id,per_genrevarchar,per_date)" +
            " values (#{perId,jdbcType=INTEGER}, " +
            "#{recordId,jdbcType=INTEGER}," +
            "#{studentId,jdbcType=INTEGER}," +
            "#{classId,jdbcType=INTEGER}," +
            "#{perGenrevarchar,jdbcType=VARCHAR}," +
            "#{perDate,jdbcType=VARCHAR})"
    })
    int insert(PerformanceStat performanceStat);
    /**
     * 根据绩效编号删除该账户信息
     * @param perId 绩效编号
     * @return 影响的行数(返回1则为成功)
     */
    @Delete({"delete from performance_stat" +
            " where per_id = #{perId,jdbcType=INTEGER}"})
    int deleteByPrimaryKey(Integer perId);
    /**
     * 根据绩效信息修改其数据
     * @param performanceStat 绩效对象
     * @return 影响的行数(返回1则为成功)
     */
    @Update({
            "update performance_stat" +
                    " set record_id = #{recordId,jdbcType=INTEGER}," +
                    " student_id = #{studentId,jdbcType=INTEGER},"+
                    " class_id = #{classId,jdbcType=INTEGER},"+
                    " per_genrevarchar = #{perGenrevarchar,jdbcType=VARCHAR},"+
                    " per_date = #{perDate,jdbcType=VARCHAR}"+
                    " where per_id = #{perId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(PerformanceStat performanceStat);
    /**
     * 根据绩效编号查询指定的信息
     * @param perId 绩效编号
     * @return 绩效对象
     */
    @Select({
            "select" +
                    " per_id, record_id,student_id,class_id,per_genrevarchar,per_date" +
            " from performance_stat" +
            " where per_id = #{perId,jdbcType=INTEGER}"
    })
    @Results(id = "PerformanceStatMaps",value = {
            @Result(id = true,column = "per_id",property = "perId" ),
            @Result(column = "record_id",property = "recordId"),
            @Result(column = "student_id",property = "studentId"),
            @Result(column = "class_id",property = "classId"),
            @Result(column = "per_genrevarchar",property = "perGenrevarchar"),
            @Result(column = "per_date",property = "perDate")
    })

    PerformanceStat selectByPrimaryKey(Integer perId);

    /**
     * 按条件分页查询绩效数据集合
     * @param rows 每页的行数
     * @param page 页码
     * @param condition 条件参数
     * @return 绩效对象集合
     */
    @Select("SELECT * " +
            "FROM performance_stat p " +
            "JOIN record r " +
            "ON p.record_id=r.record_id " +
            "JOIN student_manage s " +
            "ON p.student_id=s.student_id " +
            "JOIN class c " +
            "ON p.class_id=c.class_id " +
            "where 1=1 ${condition} limit #{page},#{rows}")
    @Results(id = "PerformanceStatMap",value = {
            @Result(column = "per_id", property = "perId", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "record_id", property = "recordId", jdbcType = JdbcType.INTEGER),
            @Result(column = "student_id", property = "studentId", jdbcType = JdbcType.INTEGER),
            @Result(column = "class_id", property = "classId", jdbcType = JdbcType.INTEGER),
            @Result(column = "per_genrevarchar", property = "perGenrevarchar", jdbcType = JdbcType.INTEGER),
            @Result(column = "per_date", property = "perDate", jdbcType = JdbcType.VARCHAR),
            @Result(column = "student_name", property = "studentName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "class_name", property = "className", jdbcType = JdbcType.INTEGER),
            @Result(column = "record_name", property = "recordName", jdbcType = JdbcType.INTEGER),
    })
    List<PerformanceStat> selectByPage(@Param("rows") int rows, @Param("page") int page, @Param("condition") String condition);

    /**
     * 按条件查询performanceStat表中数据行数
     * @param condition 条件参数
     * @return 数据行数
     */
    @Select("SELECT count(*) " +
            "FROM performance_stat p " +
            "JOIN record r " +
            "ON p.record_id=r.record_id " +
            "JOIN student_manage s " +
            "ON p.student_id=s.student_id " +
            "JOIN class c " +
            "ON p.class_id=c.class_id " +
            "where 1=1 ${condition}")
    int selectCount(@Param("condition") String condition);

    /**
     * 针对学员表(student_manage)进行操作
     * 根据学员名称查找其编号
     * @param studentName 学生姓名
     * @return 影响的行数(>1:成功)
     */
    @Select("SELECT student_id FROM student_manage WHERE student_name=#{studentName}")
    int selectByStudentName(@Param("studentName") String studentName);
    /**
     * 针对员工表(record)进行操作
     * 根据员工名称查找其编号
     * @param recordName 员工名称
     * @return 影响的行数(>1:成功)
     */
    @Select("SELECT record_id FROM record WHERE record_name=#{recordName}")
    int selectByRecordName(@Param("recordName")String recordName);

    /**
     * 针对班级表(class)进行操作
     * 根据班级名称查找其编号
     * @param className 班级名称
     * @return 影响的行数(>1:成功)
     */
    @Select("SELECT class_id FROM class WHERE class_name=#{className}")
    int selectByClassName(@Param("className")String className);
}
